package com.example.questionnaire;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.example.questionnaire.utils.UDPUtils;


public class UDPTestActivity extends AppCompatActivity {

    public static final String STARTURL = "startUrl";

    private EditText etIP;
    private EditText etPort;
    private EditText etMessage;
    private Toast mToast;
    private String encodStr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_udp);
        initview();

//        Intent intent = new Intent();
////        intent.putExtra(STARTURL, "");
//        intent.setClass(this, CubeAndroid.class);
//        startActivity(intent);
    }

    private void initview() {
        etIP = (EditText) findViewById(R.id.et_ip);
        etPort = (EditText) findViewById(R.id.et_port);
        etMessage = (EditText) findViewById(R.id.et_message);

        RadioGroup rgpContainer = (RadioGroup) findViewById(R.id.rgp_container);
        RadioButton rbtUTF_8 = (RadioButton) findViewById(R.id.rbt_utf);
        RadioButton rbtGBK = (RadioButton) findViewById(R.id.rbt_gbk);
        RadioButton rbtGB2312 = (RadioButton) findViewById(R.id.rbt_gb2312);

        rgpContainer.check(R.id.rbt_gb2312);
        encodStr = "gb2312";
        rgpContainer.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rbt_gb2312:
                        encodStr = "gb2312";
                        break;
                    case R.id.rbt_gbk:
                        encodStr = "GBK";
                        break;

                    case R.id.rbt_utf:
                        encodStr = "UTF-8";
                        break;
                    default:
                        break;
                }
            }
        });


        Button btnSend = (Button) findViewById(R.id.btn_send);
        btnSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String messageStr = etMessage.getText().toString();
                UDPUtils.sendMessage(messageStr, 1);
            }
        });

    }
}
